home *** CD-ROM | disk | FTP | other *** search
/ Borland JBuilder 6 / jbuilder6.iso / Taiji Applet Pack v2.7 / IPViewer / IPViewer.class (.txt) < prev    next >
Encoding:
Java Class File  |  2001-11-06  |  6.0 KB  |  208 lines

  1. import java.applet.Applet;
  2. import java.awt.Color;
  3. import java.awt.Component;
  4. import java.awt.Font;
  5. import java.awt.FontMetrics;
  6. import java.awt.Graphics;
  7. import java.awt.Image;
  8. import java.awt.MediaTracker;
  9. import java.awt.event.MouseEvent;
  10. import java.awt.event.MouseListener;
  11. import java.net.InetAddress;
  12. import java.net.URL;
  13.  
  14. public class IPViewer extends Applet implements MouseListener {
  15.    // $FF: renamed from: wi int
  16.    int field_0;
  17.    // $FF: renamed from: he int
  18.    int field_1;
  19.    private int wiBack;
  20.    private int heBack;
  21.    // $FF: renamed from: ip java.lang.String
  22.    String field_2;
  23.    String text;
  24.    Image backImage;
  25.    boolean loaded;
  26.    private String statusBarText;
  27.    private boolean isBackImage = false;
  28.    private String backImageName;
  29.    private Color backColor;
  30.  
  31.    public String getAppletInfo() {
  32.       return "Name: IPViewer\r\nAuthor: Taiji Software\r\n";
  33.    }
  34.  
  35.    public IPViewer() {
  36.       ((Component)this).addMouseListener(this);
  37.    }
  38.  
  39.    public void register() {
  40.       try {
  41.          URL u = new URL("http://www.taijisoftware.com");
  42.          ((Applet)this).getAppletContext().showDocument(u, "_blank");
  43.          ((Applet)this).stop();
  44.       } catch (Exception e) {
  45.          System.out.println(e);
  46.          ((Applet)this).stop();
  47.       }
  48.    }
  49.  
  50.    public void init() {
  51.       String codeBase = null;
  52.  
  53.       try {
  54.          codeBase = (new URL(((Applet)this).getCodeBase().toString())).getHost();
  55.          System.out.println("Copyright 1999, 2001 Taiji Software(tm)\nYour domain name is : " + codeBase);
  56.          codeBase = codeBase.toUpperCase();
  57.       } catch (Exception var11) {
  58.       }
  59.  
  60.       if (!((Applet)this).getCodeBase().toString().toUpperCase().startsWith("FILE") || ((Applet)this).getParameter("debug") != null) {
  61.          String regCode = ((Applet)this).getParameter("registration_code");
  62.          if (regCode == null) {
  63.             regCode = ((Applet)this).getParameter("reg_domain");
  64.             if (regCode == null) {
  65.                this.register();
  66.             } else {
  67.                if (regCode.length() == codeBase.length() + 4 && !codeBase.startsWith("WWW.")) {
  68.                   codeBase = "WWW." + codeBase;
  69.                } else if (regCode.length() == codeBase.length() - 4 && codeBase.startsWith("WWW.")) {
  70.                   codeBase = codeBase.substring(4);
  71.                }
  72.  
  73.                char[] chars = new char[codeBase.length()];
  74.                codeBase.getChars(0, codeBase.length(), chars, 0);
  75.                String key = new String("haricot");
  76.                char[] chars2 = new char[key.length()];
  77.                key.getChars(0, key.length(), chars2, 0);
  78.  
  79.                for(int i = 0; i < codeBase.length(); ++i) {
  80.                   int j;
  81.                   if (i >= key.length()) {
  82.                      j = i - key.length() * (i / key.length());
  83.                   } else {
  84.                      j = i;
  85.                   }
  86.  
  87.                   chars[i] += chars2[j];
  88.                   chars[i] = (char)(chars[i] - chars[i] / 26 * 26 + 97);
  89.                }
  90.  
  91.                String res = new String(chars);
  92.                if (!res.equalsIgnoreCase(regCode)) {
  93.                   this.register();
  94.                }
  95.             }
  96.          } else if (!regCode.equals("settevercsedegnamiaj") && !regCode.equals("8078")) {
  97.             this.register();
  98.          }
  99.       }
  100.  
  101.       this.getParameters();
  102.  
  103.       try {
  104.          this.field_2 = InetAddress.getLocalHost().getHostAddress();
  105.       } catch (Exception var10) {
  106.          this.field_2 = "could not read ip";
  107.       }
  108.  
  109.       if (this.isBackImage) {
  110.          this.backImage = ((Applet)this).getImage(((Applet)this).getCodeBase(), this.backImageName);
  111.          MediaTracker tracker = new MediaTracker(this);
  112.          tracker.addImage(this.backImage, 0);
  113.  
  114.          try {
  115.             tracker.waitForAll();
  116.             this.loaded = !tracker.isErrorAny();
  117.          } catch (Exception e) {
  118.             System.err.println(e);
  119.          }
  120.  
  121.          if (!this.loaded) {
  122.             ((Applet)this).stop();
  123.          }
  124.       } else {
  125.          this.loaded = true;
  126.       }
  127.  
  128.       if (this.isBackImage) {
  129.          this.wiBack = this.backImage.getWidth(this);
  130.          this.heBack = this.backImage.getHeight(this);
  131.       }
  132.  
  133.       ((Component)this).repaint();
  134.    }
  135.  
  136.    public void getParameters() {
  137.       this.field_0 = ((Component)this).getSize().width;
  138.       this.field_1 = ((Component)this).getSize().height;
  139.       this.text = ((Applet)this).getParameter("text");
  140.       this.statusBarText = ((Applet)this).getParameter("status_bar_text");
  141.       if (this.text == null) {
  142.          this.text = "Your IP is:";
  143.       }
  144.  
  145.       this.backImageName = ((Applet)this).getParameter("background_image");
  146.       if (this.backImageName != null) {
  147.          this.isBackImage = true;
  148.       }
  149.  
  150.       this.backColor = this.getColor("background_color");
  151.       ((Component)this).setBackground(this.backColor);
  152.    }
  153.  
  154.    public Color getColor(String param) {
  155.       String s = ((Applet)this).getParameter(param);
  156.       if (s != null) {
  157.          if (s.substring(0, 1).equals("#")) {
  158.             s = s.substring(1);
  159.             int i = Integer.parseInt(s, 16);
  160.             return new Color(i);
  161.          } else {
  162.             return null;
  163.          }
  164.       } else {
  165.          return null;
  166.       }
  167.    }
  168.  
  169.    public void paint(Graphics g) {
  170.       if (this.loaded) {
  171.          if (this.isBackImage & this.loaded) {
  172.             g.drawImage(this.backImage, (this.field_0 - this.wiBack) / 2, (this.field_1 - this.heBack) / 2, this);
  173.          }
  174.  
  175.          int h = (int)((float)this.field_1 / 40.0F * 12.0F);
  176.          g.setFont(new Font("TimesRoman", 1, h));
  177.          FontMetrics fm = g.getFontMetrics();
  178.          int w = fm.stringWidth(this.field_2);
  179.          int v = fm.stringWidth(this.text);
  180.          g.drawString(this.text, (this.field_0 - v) / 2, (int)((float)this.field_1 / 40.0F * 15.0F));
  181.          g.drawString(this.field_2, (this.field_0 - w) / 2, (int)((float)this.field_1 / 40.0F * 32.0F));
  182.       }
  183.    }
  184.  
  185.    public void update(Graphics g) {
  186.       this.paint(g);
  187.    }
  188.  
  189.    public void mouseClicked(MouseEvent e) {
  190.    }
  191.  
  192.    public void mouseEntered(MouseEvent e) {
  193.       if (this.statusBarText != null) {
  194.          ((Applet)this).showStatus(this.statusBarText);
  195.       }
  196.  
  197.    }
  198.  
  199.    public void mouseExited(MouseEvent e) {
  200.    }
  201.  
  202.    public void mousePressed(MouseEvent e) {
  203.    }
  204.  
  205.    public void mouseReleased(MouseEvent e) {
  206.    }
  207. }
  208.